package com.caishi.lkx.exam.deserializer;

import com.caishi.lkx.exam.ienum.BaseEnum;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class GenericEnumDeserializer<E extends Enum<E> & BaseEnum<T>, T> extends JsonDeserializer<E> {
    private final Class<E> enumClass;

    public GenericEnumDeserializer(Class<E> enumClass) {
        this.enumClass = enumClass;
    }

    @Override
    public E deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        T code = (T) p.getNumberValue();  // 读取 code，假设是数字类型
        return BaseEnum.fromCode(enumClass, code);
    }
}